package com.ssm.zy.controller;

import com.ssm.zy.common.controller.BaseController;
import com.ssm.zy.common.result.Result;
import com.ssm.zy.common.result.ResultCode;
import com.ssm.zy.pojo.User;
import com.ssm.zy.service.FollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/follow")
public class FollowController extends BaseController {
    @Autowired
    private FollowService followService;

//    查看我的粉丝：/follow/checkUserFocus无参数，用户id从jwt中取。
    @GetMapping("/checkUserFocus")
    public Result checkUserFocus(){
        Integer userId=super.userId;
        List<User> userList=followService.checkUserFocus(userId);
        return new Result(ResultCode.SUCCESS,userList);
    }
//    查看我的关注：/follow/checkPassiveFocus无参数，用户id从jwt中取。
    @GetMapping("/checkPassiveFocus")
    public Result checkPassiveFocus(){
        Integer userId=super.userId;
        List<User> userList=followService.checkPassiveFocus(userId);
        return new Result(ResultCode.SUCCESS,userList);
    }
    @PostMapping("/followUser")
    public Result addfollowUser(@RequestBody User user){ // 关注用户,如果关注了就取消关注
        Integer userId=super.userId;
        int foll=  followService.addfollowUser(userId,user.getId());
        if (foll>0){
            return Result.ok();
        }
        return Result.err();
    }
    @GetMapping("/toCheckUserFocus")
    public Result toCheckUserFocus(Integer userId){
        List<User> userList=followService.checkUserFocus(userId);
        return new Result(ResultCode.SUCCESS,userList);
    }

    @GetMapping("/toCheckPassiveFocus")
    public Result toCheckPassiveFocus(Integer userId){
        List<User> userList=followService.checkPassiveFocus(userId);
        return new Result(ResultCode.SUCCESS,userList);
    }
}
